
<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    
    :title="title"
   :width="conf.width"
    draggable
      align-center="true" 
    :close-on-click-modal="false"
  >
  <el-form :model="form"  ref="form" :rules="rules_aaaxn">
    <el-row>
    <el-col :span="24">
    <!-- {"index":30,"raw":"title","name":"title","cname":"Title","type":{"raw":"varchar(128)","name":"varchar","len":128,"dlen":0},"defValue":"","allowNull":false,"constraints":["q","c","l","u","v","le","rows(1)","#like","lw(160)"],"desc":{"raw":"标题","name":"标题"}} -->
    <!--标题 输入控件 -->
    <el-form-item prop="title" label="标题" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.title"  maxlength="128" 
      :rows="1"  type="textarea" show-word-limit  placeholder="请输入标题"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":32,"raw":"plan_id","name":"plan_id","cname":"PlanId","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"0","allowNull":true,"constraints":["le","q","c","sl(dev_plan,-,#lob_id)","v"],"desc":{"raw":"研发计划","name":"研发计划"}} -->
     <!--研发计划 下拉控件 -->
    <el-form-item prop="plan_id" label="研发计划" label-width="100px" label-position="right">
      <el-select   @change="onChange_plan_id(form.plan_id,'dev_plan')" v-model="form.plan_id" style="width: 100%" filterable clearable
        placeholder="请选择研发计划" >
        <el-option v-for="item in plan_idList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":33,"raw":"related_demand","name":"related_demand","cname":"RelatedDemand","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","v","le","rows(1)","sl(prod_requirement,@plan_id,#lob_id)"],"desc":{"raw":"相关需求","name":"相关需求"}} -->
     <!--相关需求 下拉控件 -->
    <el-form-item prop="related_demand" label="相关需求" label-width="100px" label-position="right">
      <el-select   @change="onChange_related_demand(form.related_demand,'prod_requirement')" v-model="form.related_demand" style="width: 100%" filterable clearable
        placeholder="请选择相关需求" >
        <el-option v-for="item in related_demandList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":34,"raw":"dev_task","name":"dev_task","cname":"DevTask","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le","rows(1)","sl(dev_task,@related_demand,#lob_id)"],"desc":{"raw":"开发任务","name":"开发任务"}} -->
     <!--开发任务 下拉控件 -->
    <el-form-item prop="dev_task" label="开发任务" label-width="100px" label-position="right">
      <el-select   v-model="form.dev_task" style="width: 100%" filterable clearable
        placeholder="请选择开发任务" >
        <el-option v-for="item in dev_taskList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":35,"raw":"test_task","name":"test_task","cname":"TestTask","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le","rows(1)","sl(test_task,@related_demand,#lob_id)"],"desc":{"raw":"测试任务","name":"测试任务"}} -->
     <!--测试任务 下拉控件 -->
    <el-form-item prop="test_task" label="测试任务" label-width="100px" label-position="right">
      <el-select   v-model="form.test_task" style="width: 100%" filterable clearable
        placeholder="请选择测试任务" >
        <el-option v-for="item in test_taskList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":36,"raw":"bug_level","name":"bug_level","cname":"BugLevel","type":{"raw":"number(1)","name":"number","len":1,"dlen":0},"defValue":"0","allowNull":false,"constraints":["c","l","le","q","u","v","sl","tp(multiselect,q)","tp(radio,c-u)","tp(tag,l)","lw(60)","color"],"desc":{"raw":"等级","name":"等级"}} -->
    <el-form-item prop="bug_level" label="等级" label-width="100px" label-position="right">
      <el-radio-group v-model="form.bug_level"   >
        <el-radio-button v-for="item in bug_levelList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":37,"raw":"bug_type","name":"bug_type","cname":"BugType","type":{"raw":"number(2)","name":"number","len":2,"dlen":0},"defValue":"","allowNull":false,"constraints":["c","l","u","v","le","sl","tp(radio,c-u)","color","lw(60)"],"desc":{"raw":"缺陷分类","name":"缺陷分类"}} -->
    <el-form-item prop="bug_type" label="缺陷分类" label-width="100px" label-position="right">
      <el-radio-group v-model="form.bug_type"   >
        <el-radio-button v-for="item in bug_typeList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":38,"raw":"reproduce_steps","name":"reproduce_steps","cname":"ReproduceSteps","type":{"raw":"text","name":"text","len":0,"dlen":0},"defValue":"","allowNull":false,"constraints":["c","u","v","le","rows(8)","tp(rtext,c-u-le)"],"desc":{"raw":"重现步骤","name":"重现步骤"}} -->
    <!--重现步骤 输入控件 -->
    <el-form-item prop="reproduce_steps" label="重现步骤" label-width="100px" label-position="right">
      <rtext :html="form.reproduce_steps" :rows="8" @onChange="onRtextreproduce_stepsChange"></rtext>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":42,"raw":"assigned_to","name":"assigned_to","cname":"AssignedTo","type":{"raw":"number(8)","name":"number","len":8,"dlen":0},"defValue":"","allowNull":true,"constraints":["l","le","c","v","sl(dmaster,-,#lob_id)","tp(radio,c-w)","w","ps(full)","lw(60)"],"desc":{"raw":"指派","name":"指派"}} -->
    <el-form-item prop="assigned_to" label="指派" label-width="100px" label-position="right">
      <el-radio-group v-model="form.assigned_to"   >
        <el-radio-button v-for="item in assigned_toList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":45,"raw":"os","name":"os","cname":"Os","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le"],"desc":{"raw":"操作系统","name":"操作系统"}} -->
    <!--操作系统 输入控件 -->
    <el-form-item prop="os" label="操作系统" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.os"  maxlength="32" 
      :rows="0"  placeholder="请输入操作系统"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":46,"raw":"browser","name":"browser","cname":"Browser","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le"],"desc":{"raw":"浏览器","name":"浏览器"}} -->
    <!--浏览器 输入控件 -->
    <el-form-item prop="browser" label="浏览器" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.browser"  maxlength="32" 
      :rows="0"  placeholder="请输入浏览器"  />
      </el-form-item>
    </el-col>
    </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        title:"缺陷管理",
        visible: false,
        width:"70%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
rules_aaaxn:{
    title:[{required:true,message:"请输入标题",trigger: 'blur'}],
    plan_id:[{required:false,message:"请输入研发计划",trigger: 'blur'}],
    related_demand:[{required:false,message:"请输入相关需求",trigger: 'blur'}],
    dev_task:[{required:false,message:"请输入开发任务",trigger: 'blur'}],
    test_task:[{required:false,message:"请输入测试任务",trigger: 'blur'}],
    bug_level:[{required:true,message:"请输入等级",trigger: 'blur'}],
    bug_type:[{required:true,message:"请输入缺陷分类",trigger: 'blur'}],
    reproduce_steps:[{required:true,message:"请输入重现步骤",trigger: 'blur'}],
    assigned_to:[{required:false,message:"请输入指派",trigger: 'blur'}],
    os:[{required:false,message:"请输入操作系统",trigger: 'blur'}],
    browser:[{required:false,message:"请输入浏览器",trigger: 'blur'}],
  },
    form:{
        title:"",
        plan_id:"",
        related_demand:"",
        dev_task:"",
        test_task:"",
        bug_level:"",
        bug_type:"",
        reproduce_steps:"",
        assigned_to:"",
        os:"",
        browser:"",
    },
    plan_idList:[],
    related_demandList:[],
    dev_taskList:[],
    test_taskList:[],
    bug_levelList:[],
    bug_typeList:[],
    assigned_toList:[],
    }
  },
  methods: {
    show(fm = {}) {
      this.title = fm.$title || this.title
      this.conf.visible = true;
      this.loadEnums_aaaxn()
      let local = {}
        //将数据保存到window缓存中
      local = window.test_bug || {}
      let cache = Object.assign(local,fm)
      this.form = Object.assign(cache,this.$route.params)
      this.onChange_plan_id(this.$route.params["plan_id"]||this.form["plan_id"],"dev_plan")
      this.onChange_related_demand(this.$route.params["related_demand"]||this.form["related_demand"],"prod_requirement")
      this.onChange_related_demand(this.$route.params["related_demand"]||this.form["related_demand"],"prod_requirement")
    },
    save(){
      this.$refs.form.validate((v=>{
          if(v) this.onSave()
      }))
    },
    onSave(){
        let that = this
        let postForm = Object.assign({},this.form)
        //将数据保存到window缓存中
        window.test_bug = postForm
        postForm.lob_id = this.$theia.user.get("lob_id")
        //保存数据
        this.$theia.http.post("/ws/test/bug",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '缺陷管理保存成功',duration:5000})
            that.hide()
            that.$theia.enum.clear("")
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg= `缺陷管理保存失败(${code})`
            msg = code == 909? msg+"数据重复，请修改后重试":msg
            that.$notify.error({title: '失败',message:msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
    onRtextreproduce_stepsChange(text,urls){
      this.form.reproduce_steps = text
      this.form.reproduce_steps_urls = (urls||[]).join(",")
    },
    onUploadSuccess(response){
    },
    onChange_plan_id(val,tp){
      if (!val) {
        this.related_demandList = []
        this.form.related_demand = null
        return
      }
      this.related_demandList = this.$theia.enum.get("prod_requirement",val, this.$theia.user.get("lob_id"))||[]
      this.form.related_demand =this.related_demandList.length>0?(this.related_demandList[0]||{}).value:null
      //cxtriger:[{"index":34,"raw":"dev_task","name":"dev_task","cname":"DevTask","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le","rows(1)","sl(dev_task,@related_demand,#lob_id)"],"desc":{"raw":"开发任务","name":"开发任务"}} {"index":35,"raw":"test_task","name":"test_task","cname":"TestTask","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","v","le","rows(1)","sl(test_task,@related_demand,#lob_id)"],"desc":{"raw":"测试任务","name":"测试任务"}}]
      this.onChange_related_demand(this.form.related_demand,"dev_task")
      this.onChange_related_demand(this.form.related_demand,"test_task")
    },
    onChange_related_demand(val,tp){
      if (!val) {
        this.dev_taskList = []
        this.form.dev_task = null
        return
      }
      this.dev_taskList = this.$theia.enum.get("dev_task",val, this.$theia.user.get("lob_id"))||[]
      this.form.dev_task =this.dev_taskList.length>0?(this.dev_taskList[0]||{}).value:null
      if (!val) {
        this.test_taskList = []
        this.form.test_task = null
        return
      }
      this.test_taskList = this.$theia.enum.get("test_task",val, this.$theia.user.get("lob_id"))||[]
      this.form.test_task =this.test_taskList.length>0?(this.test_taskList[0]||{}).value:null
    },
    loadEnums_aaaxn(){
        //研发计划
        this.plan_idList = this.$theia.enum.get("dev_plan","",this.$theia.user.get("lob_id"),false,"")
        //相关需求
        this.related_demandList = this.$theia.enum.get("prod_requirement",((this.form_aaaxn||this.form).plan_id||"")+"",this.$theia.user.get("lob_id"),false,"")
        //开发任务
        this.dev_taskList = this.$theia.enum.get("dev_task",((this.form_aaaxn||this.form).related_demand||"")+"",this.$theia.user.get("lob_id"),false,"")
        //测试任务
        this.test_taskList = this.$theia.enum.get("test_task",((this.form_aaaxn||this.form).related_demand||"")+"",this.$theia.user.get("lob_id"),false,"")
        //等级
        this.bug_levelList = this.$theia.enum.get("bug_level","","" ,false,"")
        //缺陷分类
        this.bug_typeList = this.$theia.enum.get("bug_type","","" ,false,"")
        //指派
        this.assigned_toList = this.$theia.enum.get("dmaster","",this.$theia.user.get("lob_id"),false,"")
    },

},
}
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 80px;
  height: 80px;
  display: block;
}
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>